﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TRTCMain.Controls
{
    public partial class HandButton : UserControl
    {
        private bool isChecked = false;
        public delegate void CheckStatusChangedHandler(bool isChecked);
        public event CheckStatusChangedHandler CheckStatusChanged;

        public HandButton()
        {
            InitializeComponent();
            this.label.Click += HandButton_Click;
            this.pictureBox.Click += HandButton_Click;
            this.MouseMove += MicroButton_MouseMove; ;
            this.MouseLeave += MicroButton_MouseLeave; ;
            pictureBox.MouseMove += PictureBox_MouseMove; ;
            pictureBox.MouseLeave += PictureBox_MouseLeave; ;
            label.MouseMove += Label_MouseMove; ;
            label.MouseLeave += Label_MouseLeave;
        }

        private void Label_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(32, 34, 36);
        }

        private void Label_MouseMove(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.FromArgb(69, 70, 72);
        }

        private void PictureBox_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(32, 34, 36);
        }

        private void PictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.FromArgb(69, 70, 72);
        }

        private void MicroButton_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(32, 34, 36);
        }

        private void MicroButton_MouseMove(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.FromArgb(69, 70, 72);
        }

        public bool IsChecked {
            get { return this.isChecked; }
            set {
                this.isChecked = value;
                ChangeStatus(value);
            }
        }

        private void HandButton_Click(object sender, EventArgs e)
        {
            IsChecked = !IsChecked;
        }

        private void ChangeStatus(bool isChecked) {
            if (IsChecked)
            {
                this.pictureBox.Image = Properties.Resources.big_hand;
                this.label.Text = "放下";
            }
            else
            {
                this.pictureBox.Image = Properties.Resources.voter;
                this.label.Text = "举手";
            }

            CheckStatusChanged?.Invoke(IsChecked);
        }
    }
}
